package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.DecorationRequest;
import com.ytjj.qmyx.admin.model.request.PageDecorationRequest;
import com.ytjj.qmyx.admin.model.request.PageRequest;
import com.ytjj.qmyx.admin.service.PageDecorationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * 
 * @Version: 1.0
 *
 * 页面装修管理
 */
@RestController
@RequestMapping("/pageDecoration")
public class PageDecorationController {

	@Resource
	private PageDecorationService pageDecorationService;

	@GetMapping("/list")
	@OperLog(operModule = "页面装修管理", operDesc = "页面列表", operType = SysLogConstants.OPERATION_SELECT)
	public CommonResult getList(PageDecorationRequest request) {
		return CommonResult.success(pageDecorationService.getList(request));
	}

	@GetMapping("/productList")
	public CommonResult selectList(PageRequest pageRequest) {
		return CommonResult.success(pageDecorationService.selectList(pageRequest));
	}

	@GetMapping("/searchProduct")
	public CommonResult getList(@RequestParam String productName) {
		return CommonResult.success(pageDecorationService.searchProduct(productName));
	}

	@PostMapping("/insert")
	@OperLog(operModule = "页面装修管理", operDesc = "新增页面", operType = SysLogConstants.OPERATION_ADD)
	public CommonResult insertPage(@RequestBody DecorationRequest[] request) {
		pageDecorationService.insertPage(request);
		return CommonResult.success();
	}

	@GetMapping("/getPageById")
	@OperLog(operModule = "页面装修管理", operDesc = "页面详情", operType = SysLogConstants.OPERATION_SELECT)
	public CommonResult getPageById(@RequestParam Integer id) {
		return CommonResult.success(pageDecorationService.decoraList(id));
	}

	@PostMapping("/updatePageById")
	@OperLog(operModule = "页面装修管理", operDesc = "编辑", operType = SysLogConstants.OPERATION_UPDATE)
	public CommonResult updatePageById(@RequestBody DecorationRequest[] request) {
		pageDecorationService.updatePageById(request);
		return CommonResult.success();
	}

	@GetMapping("/delete")
	@OperLog(operModule = "页面装修管理", operDesc = "移除", operType = SysLogConstants.OPERATION_DELETE)
	public CommonResult deletePage(@RequestParam Integer id) {
		pageDecorationService.updateStatus(id);
		return CommonResult.success();
	}
}
